package com.zl.learning.object.clone;

import java.io.Serializable;
import java.util.List;

public class ClassRoom implements Cloneable, Serializable {
    private int id;
    private List<User> users;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

        @Override
    public ClassRoom clone(){
        try {
            return (ClassRoom) super.clone();
        } catch (CloneNotSupportedException e) {
            e.printStackTrace();
        }
        return null;
    }

//    @Override
//    public ClassRoom clone() {
//        try {
//            ClassRoom c = (ClassRoom) super.clone();
//            c.setUsers(c.users.stream().map(User::clone).collect(Collectors.toList()));;
//            return c;
//        }catch (CloneNotSupportedException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

//    @Override
//    public ClassRoom clone() {
//        try {
//            ByteArrayOutputStream bo = new ByteArrayOutputStream();
//            ObjectOutputStream oo = new ObjectOutputStream(bo);
//            oo.writeObject(this);
//            ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
//            ObjectInputStream oi = new ObjectInputStream(bi);
//            return (ClassRoom) oi.readObject();
//        } catch (IOException | ClassNotFoundException e) {
//            e.printStackTrace();
//        }
//        return null;
//    }

}
